package cn.lyvust.demo03;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
/**
 * Description:
 * date: 2021-6-9 21:00
 *
 * @author Guo_guo
 * @since JDK 1.8
 */
public class Server01 {
    public static void main(String[] args) {
        try {
            ServerSocket ss = new ServerSocket(8888);
            System.out.println("服务器已启动");
            Socket s = ss.accept();
            //构建IO流
            while(true){
                BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
                String mess = br.readLine();
                System.out.println("你好，客户端，我是服务端，你发的内容是:" + mess);
                BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
                //为了证明是服务器返回的数据，我对mess修改在发送到客户端
                String str = "服务器>>"+mess+"\n";
                bw.write(str);
                bw.flush();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
